home *** CD-ROM | disk | FTP | other *** search
/ PC Master 5 / PC MASTER 5.iso / DELPHI / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-25  |  2.7 KB  |  113 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, MPlayer;
  8.  
  9. type
  10.   TformMain = class(TForm)
  11.     MediaPlayer: TMediaPlayer;
  12.     timerHora: TTimer;
  13.     buttonFale: TButton;
  14.     labelHora: TLabel;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure timerHoraTimer(Sender: TObject);
  17.     procedure buttonFaleClick(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.     Sons : String;
  21.     procedure Fala(Arquivo:String);
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   formMain: TformMain;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TformMain.FormCreate(Sender: TObject);
  34. begin
  35.   {Seta a localizaτπo da pasta SONS, dentro da pasta do
  36.    nosso programa, onde quer que ele esteja}
  37.   Sons := ExtractFilePath(Application.ExeName);
  38.   if Sons[Length(Sons)]<>'\' then Sons := Sons + '\';
  39.   Sons := Sons + 'SONS\';
  40.   {Executa a rotina do Timer, para exibir a hora logo no inφcio}
  41.   timerHoraTimer(timerHora);
  42. end;
  43.  
  44. procedure TformMain.timerHoraTimer(Sender: TObject);
  45. begin
  46.   {Exibe a hora}
  47.   labelHora.Caption := Copy(TimetoStr(Time),1,5);
  48. end;
  49.  
  50. {"Fala" o arquivo especificado}
  51. procedure TformMain.Fala(Arquivo:String);
  52. begin
  53.   {Adiciona o caminho e a extensπo .WAV ao arquivo}
  54.   Arquivo := Sons+Arquivo+'.WAV';
  55.   {Se o arquivo nπo existir, sai da procedure}
  56.   if not FileExists(Arquivo) then Exit;
  57.   {"Toca" o arquivo}
  58.   MediaPlayer.FileName := Arquivo;
  59.   try
  60.     MediaPlayer.Open;
  61.     MediaPlayer.Play;
  62.     {MantΘm o windows "trabalhando" sem sair da procedure
  63.      enquanto o arquivo estiver sendo reproduzido}
  64.     While MediaPlayer.Position < MediaPlayer.Length do
  65.       Application.ProcessMessages;
  66.   finally
  67.     MediaPlayer.Close;
  68.   end;
  69. end;
  70.  
  71. procedure TformMain.buttonFaleClick(Sender: TObject);
  72. var Hora, Minuto : Integer;
  73. begin
  74.   {Converte a hora e o minuto p/ inteiros}
  75.   Hora := StrToInt(Copy(labelHora.Caption,1,2));
  76.   Minuto := StrToInt(Copy(labelHora.Caption,4,2));
  77.   {"Fala" a hora}
  78.   if Hora<=20 then
  79.   begin
  80.     Case Hora of
  81.     1:Fala('1h');
  82.     2:Fala('2h');
  83.     else Fala(IntToStr(Hora));
  84.     end;
  85.   end else
  86.   begin
  87.     Fala(IntToStr((Hora div 10)*10));
  88.     if Hora mod 10 <> 0 then
  89.     begin
  90.       Fala('e');
  91.       Fala(IntToStr(Hora mod 10));
  92.     end;
  93.   end;
  94.   if Hora<>1 then Fala('horas') else Fala('hora');
  95.   {"Fala" os minutos, se necessßrio}
  96.   if Minuto<>0 then
  97.   begin
  98.     Fala('e');
  99.     if Minuto<=20 then Fala(IntToStr(Minuto)) else
  100.     begin
  101.       Fala(IntToStr((Minuto div 10)*10));
  102.       if Minuto mod 10 <> 0 then
  103.       begin
  104.         Fala('e');
  105.         Fala(IntToStr(Minuto mod 10));
  106.       end;
  107.     end;
  108.     if Minuto<>1 then Fala('minutos') else Fala('minuto');
  109.   end;
  110. end;
  111.  
  112. end.
  113.